package pdamh.model.util;

import junit.framework.TestCase;

import static pdamh.model.util.Calculador.*;


public class CalculadorTest extends TestCase {

	public void testSomar() {
		assertEquals(0.01, somar(0.005,0.005));
		assertEquals(0.01, somar(0.007999,0.002001));
		assertEquals(0.002222, somar(0.001111,0.001111));
		assertEquals(0.0, somar(-0.001111,0.001111));
		assertEquals(-0.001111, somar(-0.001111,0));
		double x = 0;
		for (int i = 0; i < 10000; i++)
			x = somar(x, 0.01);
		assertEquals(100.0, x);
		x = 0;
		for (int i = 0; i < 10000; i++)
			x = somar(x, 0.009);
		assertEquals(90.0, x);
		for (int i = 0; i < 10000; i++)
			x = somar(x, 0.009);
		assertEquals(180.0, x);
	}

	public void testSubtrair() {
		assertEquals(0.0, subtrair(1.11111,1.11111));
		assertEquals(-0.09, subtrair(0,0.09));
		double x = 0;
		for (int i = 0; i < 10000; i++)
			x = subtrair(x, 0.009);
		assertEquals(-90.0, x);
	}

	public void testPotencia() {
		assertEquals(729.0, potencia(9,3));
		assertEquals(2.0, potencia(4,0.5));
		assertEquals(3125.0, potencia(5,5));
		assertEquals(potencia(25,2.5), potencia(5,5));
	}

	public void testMultiplicar() {
		assertEquals(5.0, multiplicar(0.5,10));
		assertEquals(0.9, multiplicar(0.09,10));
		assertNotSame(10*0.09, multiplicar(0.09,10));
	}

	public void testDividir() {
		assertEquals(0.0001, dividir(1,10000));
		assertEquals(0.0, dividir(0, 1));
		assertEquals(2.0, dividir(25, 12.5));
	}

	public void testRaizQuadrada() {
		assertEquals(2.0, raizQuadrada(4));
		assertEquals(5.0, raizQuadrada(25));
		assertEquals(25.0, raizQuadrada(625));
	}

}
